package com.cnap.multiclouldmgmt.model.k8sModels;

import com.cnap.multiclouldmgmt.model.K8sClusterInfoModel;
import com.cnap.multiclouldmgmt.model.microSvc.MicroServicePO;
import com.cnap.multiclouldmgmt.util.CnapCloudMgmtConstants;
import com.cnap.multiclouldmgmt.util.DateUtils;
import io.fabric8.kubernetes.api.model.ServicePort;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * 集群组件基础信息
 * @author dyq
 */
@ApiModel(value = "com.cnap.multiclouldmgmt.model.k8sModels.SvcModel",description = "服务信息")
public class SvcModel extends K8sClusterInfoModel {

    //服务名称
    @ApiModelProperty(value = "服务名称")
    private String svcName;

    //服务的类型
    @ApiModelProperty(value = "服务的类型")
    private String svcType;

    //命名空间
    @ApiModelProperty(value = "命名空间")
    private String namespace;

    //clusterIp
    @ApiModelProperty(value = "clusterIp")
    private String clusterIp;

    //port
    @ApiModelProperty(value = "port")
    private String port;

    //targetport
    @ApiModelProperty(value = "targetport")
    private String targetPort;

    //NodePort
    @ApiModelProperty(value = "NodePort")
    private String NodePort;

    //选择器字符
    @ApiModelProperty(value = "选择器字符")
    private String seclector;

    //选择器们
    @ApiModelProperty(value = "选择器们")
    private List<KeyValueModel> seclectorList;

    //选择器map
    @ApiModelProperty(value = "选择器map")
    private Map<String,String> seclectorMap;

    //状态
    @ApiModelProperty(value = "状态")
    private String status;

    //创建时间
    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    //部署的yaml
    @ApiModelProperty(value = "部署的yaml")
    private String yaml;

    //创建时间格式化
    @ApiModelProperty(value = "创建时间格式化")
    private String createTimeStr;

    @ApiModelProperty(value = "所有的端口")
    private List<ServicePort> servicePorts;

    @ApiModelProperty(value = "svc对应的微服务名称")
    private String microServiceName;

    @ApiModelProperty(value = "svc对应的微服务相关信息")
    private MicroServicePO microServicePO;


    @ApiModelProperty(value = "microSvcId")
    private String microSvcId;

    @ApiModelProperty(value = "微服务的告警等级")
    private String svcAlarm;

    @ApiModelProperty(value = "是否是GPU应用，CPU或者GPU")
    private String arch;

    @ApiModelProperty(value = "如果是微服务，他的访问路径")
    private String path;

    @ApiModelProperty(value = "svcType，类似Ai推理这种")
    private String businessSceneSvcType;

    /**
     * get
     *
     * @return MicroSvcId
     */
    public String getMicroSvcId() {
        if (microServicePO != null){
            microSvcId = microServicePO.getId();
        }
        return microSvcId;
    }

    /**
     * get
     *
     * @return Arch
     */
    @Override
    public String getArch() {

        if (StringUtils.isEmpty(arch)){

            if (StringUtils.endsWithIgnoreCase(getK8sClusterName(), CnapCloudMgmtConstants.ARCH_GPU)){
                arch = CnapCloudMgmtConstants.ARCH_GPU;
            }else {
                arch = CnapCloudMgmtConstants.ARCH_CPU;
            }

        }
        return arch;
    }

    /**
     * set
     *
     * @param arch arch
     */
    @Override
    public void setArch(String arch) {
        this.arch = arch;
    }

    /**
     * set
     *
     * @param microSvcId microSvcId
     */
    public void setMicroSvcId(String microSvcId) {
        this.microSvcId = microSvcId;
    }

    /**
     * get
     *
     * @return SvcAlarm
     */
    public String getSvcAlarm() {
        return svcAlarm;
    }

    /**
     * set
     *
     * @param svcAlarm svcAlarm
     */
    public void setSvcAlarm(String svcAlarm) {
        this.svcAlarm = svcAlarm;
    }

    public String getCreateTimeStr() {

        if ((StringUtils.isEmpty(createTimeStr))
                &&(createTime != null)){
            createTimeStr = DateUtils.changeDateFormatYYYYMMDDHHMMSS(createTime);
        }

        return createTimeStr;
    }

    /**
     * get
     *
     * @return SvcName
     */
    public String getSvcName() {
        return svcName;
    }

    /**
     * set
     *
     * @param svcName svcName
     */
    public void setSvcName(String svcName) {
        this.svcName = svcName;
    }

    /**
     * get
     *
     * @return SvcType
     */
    public String getSvcType() {
        return svcType;
    }

    /**
     * set
     *
     * @param svcType svcType
     */
    public void setSvcType(String svcType) {
        this.svcType = svcType;
    }

    /**
     * get
     *
     * @return Namespace
     */
    public String getNamespace() {
        return namespace;
    }

    /**
     * set
     *
     * @param namespace namespace
     */
    public void setNamespace(String namespace) {
        this.namespace = namespace;
    }

    /**
     * get
     *
     * @return ClusterIp
     */
    public String getClusterIp() {
        return clusterIp;
    }

    /**
     * set
     *
     * @param clusterIp clusterIp
     */
    public void setClusterIp(String clusterIp) {
        this.clusterIp = clusterIp;
    }

    /**
     * get
     *
     * @return Port
     */
    public String getPort() {
        return port;
    }

    /**
     * set
     *
     * @param port port
     */
    public void setPort(String port) {
        this.port = port;
    }

    /**
     * get
     *
     * @return TargetPort
     */
    public String getTargetPort() {
        return targetPort;
    }

    /**
     * set
     *
     * @param targetPort targetPort
     */
    public void setTargetPort(String targetPort) {
        this.targetPort = targetPort;
    }

    /**
     * get
     *
     * @return NodePort
     */
    public String getNodePort() {
        return NodePort;
    }

    /**
     * set
     *
     * @param nodePort nodePort
     */
    public void setNodePort(String nodePort) {
        NodePort = nodePort;
    }

    /**
     * get
     *
     * @return Seclector
     */
    public String getSeclector() {
        return seclector;
    }

    /**
     * set
     *
     * @param seclector seclector
     */
    public void setSeclector(String seclector) {
        this.seclector = seclector;
    }

    /**
     * get
     *
     * @return SeclectorList
     */
    public List<KeyValueModel> getSeclectorList() {
        return seclectorList;
    }

    /**
     * set
     *
     * @param seclectorList seclectorList
     */
    public void setSeclectorList(List<KeyValueModel> seclectorList) {
        this.seclectorList = seclectorList;
    }

    /**
     * get
     *
     * @return SeclectorMap
     */
    public Map<String, String> getSeclectorMap() {
        return seclectorMap;
    }

    /**
     * set
     *
     * @param seclectorMap seclectorMap
     */
    public void setSeclectorMap(Map<String, String> seclectorMap) {
        this.seclectorMap = seclectorMap;
    }

    /**
     * get
     *
     * @return Status
     */
    public String getStatus() {
        return status;
    }

    /**
     * set
     *
     * @param status status
     */
    public void setStatus(String status) {
        this.status = status;
    }

    /**
     * get
     *
     * @return CreateTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * set
     *
     * @param createTime createTime
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * get
     *
     * @return Yaml
     */
    public String getYaml() {
        return yaml;
    }

    /**
     * set
     *
     * @param yaml yaml
     */
    public void setYaml(String yaml) {
        this.yaml = yaml;
    }

    /**
     * set
     *
     * @param createTimeStr createTimeStr
     */
    public void setCreateTimeStr(String createTimeStr) {
        this.createTimeStr = createTimeStr;
    }

    /**
     * get
     *
     * @return ServicePorts
     */
    public List<ServicePort> getServicePorts() {
        return servicePorts;
    }

    /**
     * set
     *
     * @param servicePorts servicePorts
     */
    public void setServicePorts(List<ServicePort> servicePorts) {
        this.servicePorts = servicePorts;
    }

    /**
     * get
     *
     * @return MicroServiceName
     */
    public String getMicroServiceName() {
        return microServiceName;
    }

    /**
     * set
     *
     * @param microServiceName microServiceName
     */
    public void setMicroServiceName(String microServiceName) {
        this.microServiceName = microServiceName;
    }

    /**
     * get
     *
     * @return MicroServicePO
     */
    public MicroServicePO getMicroServicePO() {
        return microServicePO;
    }

    /**
     * set
     *
     * @param microServicePO microServicePO
     */
    public void setMicroServicePO(MicroServicePO microServicePO) {
        this.microServicePO = microServicePO;
    }

    /**
     * get
     *
     * @return Path
     */
    public String getPath() {
        return path;
    }

    /**
     * set
     *
     * @param path path
     */
    public void setPath(String path) {
        this.path = path;
    }

    /**
     * get
     *
     * @return BusinessSceneSvcType
     */
    public String getBusinessSceneSvcType() {
        return businessSceneSvcType;
    }

    /**
     * set
     *
     * @param businessSceneSvcType businessSceneSvcType
     */
    public void setBusinessSceneSvcType(String businessSceneSvcType) {
        this.businessSceneSvcType = businessSceneSvcType;
    }
}
